package ynu.edu.ky_elm_springboot3.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import ynu.edu.ky_elm_springboot3.po.Orders;
import ynu.edu.ky_elm_springboot3.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Tag(name = "订单相关接口")
@RestController
@RequestMapping("/OrdersController")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;
    
    @Operation(summary = "创建订单")
    @PostMapping("/createOrders")
    public int createOrders(@RequestParam("userId") String userId,
                           @RequestParam("businessId") Integer businessId,
                           @RequestParam("daId") Integer daId,
                           @RequestParam("orderTotal") Double orderTotal) {
        Orders orders = new Orders();
        orders.setUserId(userId);
        orders.setBusinessId(businessId);
        orders.setDaId(daId);
        orders.setOrderTotal(new BigDecimal(orderTotal));
        orders.setOrderDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return ordersService.createOrders(orders);
    }
    
    @Operation(summary = "根据订单ID查询订单")
    @GetMapping("/getOrdersById")
    public Orders getOrdersById(@RequestParam("orderId") Integer orderId) {
        return ordersService.getOrdersById(orderId);
    }
    
    @Operation(summary = "查询用户订单")
    @GetMapping("/listOrdersByUserId")
    public List<Orders> listOrdersByUserId(@RequestParam("userId") String userId) {
        return ordersService.listOrdersByUserId(userId);
    }
} 